/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Dashboard.java
 *
 * Created on Jul 11, 2011, 7:30:25 PM
 */
package panels;

import javax.swing.JTabbedPane;
import main.MainFrame;
import obj.Page;
import util.DashboardUtil;
import util.LoggedInUser;

/**
 *
 * @author jalmos, nknowles
 */
public class Dashboard extends javax.swing.JPanel {

  String[] memberInfoTabs;
  String[] appointmentTabs;

  /** Creates new form Dashboard */
  public Dashboard() {
    initComponents();

    //memberInfoTabs = new String[]{"View Panel", "Edit Panel"};

    displayMemberInformation();
    setPermissions();
  }

  private void displayMemberInformation() {
    tabPane.removeAll();
    //tabPane.addTab("Edit Panel", new EditMemberInformationPanel());
    tabPane.addTab("Upload File", new UploadFile());
    tabPane.addTab("Delete Panel", new DeletePatientPanel());
    
    this.validate();
  }

  private void displayAppointmentInformation() {
    // TODO add your handling code here:
    tabPane.removeAll();
    //try {
    //tabPane.addTab("View Appointment", ViewAppointmentPanel.getInstance());
    tabPane.addTab("Create Appointment", CreateAppointmentPanel.getInstance());
    //tabPane.addTab("Edit Appointment", EditAppointmentPanel.getInstance());
   // tabPane.addTab("Appointment", new AppointmentPanel());
    //} catch (SQLException ex) {
    //Logger.getLogger(Dashboard.class.getName()).log(Level.SEVERE, null, ex);
    //}
    tabPane.addTab("Appointment", new AppointmentPanel());
  }

  public static JTabbedPane getTabPane() {
    return tabPane;
  }

  /** This method is called from within the constructor to
   * initialize the form.
   * WARNING: Do NOT modify this code. The content of this method is
   * always regenerated by the Form Editor.
   */
  @SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {
    java.awt.GridBagConstraints gridBagConstraints;

    sidePane = new javax.swing.JPanel();
    btnSearchForPatient = new javax.swing.JButton();
    memberInfoButton = new javax.swing.JButton();
    patientInformationButton = new javax.swing.JButton();
    appointmentButton = new javax.swing.JButton();
    adminButton = new javax.swing.JButton();
    logoutButton = new javax.swing.JButton();
    jPanel1 = new javax.swing.JPanel();
    tabPane = new javax.swing.JTabbedPane();

    setBackground(new java.awt.Color(84, 84, 84));
    setPreferredSize(new java.awt.Dimension(800, 600));
    setLayout(new java.awt.BorderLayout());

    sidePane.setAlignmentX(0.0F);
    sidePane.setAlignmentY(1.0F);
    sidePane.setOpaque(false);
    sidePane.setLayout(new java.awt.GridLayout(0, 1));

    btnSearchForPatient.setText("Search for Patient");
    btnSearchForPatient.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        btnSearchForPatientActionPerformed(evt);
      }
    });
    sidePane.add(btnSearchForPatient);

    memberInfoButton.setText("<html>\n<p style=\"text-align: center;\">\nMember <br/>\nInformation\n</p>\n</html>");
    memberInfoButton.setMaximumSize(null);
    memberInfoButton.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        memberInfoButtonActionPerformed(evt);
      }
    });
    sidePane.add(memberInfoButton);

    patientInformationButton.setText("<html>\n<p style=\"text-align: center;\">\nPatient <br/>\nInformation\n</p>\n</html>");
    patientInformationButton.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        patientInformationButtonActionPerformed(evt);
      }
    });
    sidePane.add(patientInformationButton);

    appointmentButton.setText("Appointments");
    appointmentButton.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        appointmentButtonActionPerformed(evt);
      }
    });
    sidePane.add(appointmentButton);

    adminButton.setText("Admin Control");
    adminButton.setMaximumSize(null);
    adminButton.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        adminButtonActionPerformed(evt);
      }
    });
    sidePane.add(adminButton);

    logoutButton.setText("Logout");
    logoutButton.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        logoutButtonActionPerformed(evt);
      }
    });
    sidePane.add(logoutButton);

    add(sidePane, java.awt.BorderLayout.WEST);

    jPanel1.setOpaque(false);
    jPanel1.setLayout(new java.awt.GridBagLayout());

    tabPane.setPreferredSize(new java.awt.Dimension(600, 800));
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 1;
    gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
    gridBagConstraints.weightx = 0.1;
    gridBagConstraints.weighty = 0.1;
    gridBagConstraints.insets = new java.awt.Insets(3, 10, 15, 15);
    jPanel1.add(tabPane, gridBagConstraints);

    add(jPanel1, java.awt.BorderLayout.CENTER);
  }// </editor-fold>//GEN-END:initComponents

    private void memberInfoButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_memberInfoButtonActionPerformed
      displayMemberInformation();
    }//GEN-LAST:event_memberInfoButtonActionPerformed

    private void appointmentButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_appointmentButtonActionPerformed
      displayAppointmentInformation();
    }//GEN-LAST:event_appointmentButtonActionPerformed

private void logoutButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_logoutButtonActionPerformed
  MainFrame mainFrame = MainFrame.getInstance();
  Page page = new Page();
  page.setTitle("Welcome");
  mainFrame.setPanel(page);
}//GEN-LAST:event_logoutButtonActionPerformed

private void patientInformationButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_patientInformationButtonActionPerformed
  /* TODO add code to load up the tabs associated with patient information
  /*
   * personal info (various text fields like address, zip, marital status, etc.)
   * link to user account if possible insurance (current and historical)
   * medical history (this can be a history of visits/treatment record)
   * co-insurance payments (history of payments associated w visits)
   * allergies (simple)
   * medications (both prescribed from treatments and not)
   * primary doctor (link to doctor record in EMIS)
   */

  // Personal Information
  tabPane.removeAll();
  tabPane.add("Personal", new PatientPersonalInformationPanel());
  tabPane.add("Phone", new PatientPhoneInformationPanel());
  tabPane.add("Address", new PatientAddressInformationPanel());

  // Allergies
  tabPane.add("Allergies", new PatientAllergiesPanel());

  // Medications
  tabPane.add("Medications", new PatientMedicationsPanel());

  //Primary Doctor
  tabPane.add("Primary Doctor", new PatientPrimaryDoctorPanel());

  //Insurance
  tabPane.add("Insurance", new PatientInsurancePanel());

  // Co-InsurancePayments
  //tabPane.add("Payments", new PatientCoPayHistoryPanel());

  /* Medical History:
   * - Stats
   * - Reason for visit
   * - Symptoms
   * - Co-Pay
   * - Diagnoses
   */
  // Medical History
  //JTabbedPane medHistory = new JTabbedPane();
  tabPane.add("Medical History", new PatientMedicalHistoryPanel());

}//GEN-LAST:event_patientInformationButtonActionPerformed

private void adminButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_adminButtonActionPerformed
    tabPane.removeAll();
    tabPane.addTab("History", new UserHistoryPanel());
  tabPane.removeAll();
  tabPane.add("Roles", new AdminSetUserRoles());
}//GEN-LAST:event_adminButtonActionPerformed

private void btnSearchForPatientActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSearchForPatientActionPerformed
  DashboardUtil.searchForPatient();
  displayMemberInformation();
}//GEN-LAST:event_btnSearchForPatientActionPerformed
  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.JButton adminButton;
  private javax.swing.JButton appointmentButton;
  private javax.swing.JButton btnSearchForPatient;
  private javax.swing.JPanel jPanel1;
  private javax.swing.JButton logoutButton;
  private javax.swing.JButton memberInfoButton;
  private javax.swing.JButton patientInformationButton;
  private javax.swing.JPanel sidePane;
  private static javax.swing.JTabbedPane tabPane;
  // End of variables declaration//GEN-END:variables

  private void setPermissions() {

    switch (LoggedInUser.getInstance().getRoleID()) {
      // New User
      case 0:

      // Patient
      case 1:
        memberInfoButton.setVisible(false);
        appointmentButton.setVisible(false);
        patientInformationButton.setVisible(false); // hide it for now
      //tabPane.remove(1);

      // Receptionist
      case 2:

      // Nurse
      case 3:

      // Doctor
      case 4:
        adminButton.setVisible(false);

      // Admin
      case 5:
    }
  }
}
